-- parry_damage
-- create by panyl
-- 伤害减少

return {
    apply = function(prop, baseValue)
        -- 比率减少
        local v = prop[3];
        local reduce = math.modf(baseValue * v / 1000);

        -- 不能少于0
        return math.max(baseValue - reduce, 0);
    end,

    -- 受创触发
    trigger = function(who, prop, arg)
        if type(arg) ~= "number" then
            return 0;
        end

        local reduce = math.modf(arg * prop[3] / 1000);
        local damage = math.max(arg - reduce, 0);

        if prop[2] == "dream" then
            -- 梦境视界，干掉状态
            if CombatStatusM.checkStatus(who, "dream_sight") then
                -- 设置为当前回合结束
                local condition = CombatStatusM.queryCondition(who, "dream_sight");
                condition["end_round"] = CombatM.getRound();
            end
        elseif prop[2] == "asylum" then
            -- 只抵挡一次的状态
            CombatStatusM.clearStatus(who, "asylum");
        end

        return damage;
    end,

    record = function(target, prop, path)
        return false;
    end
};
